package com.example.demo.controller;

import java.math.BigDecimal;
import java.util.List;
import java.util.concurrent.ExecutionException;

import javax.validation.Valid;

import com.alibaba.fastjson.JSON;
import com.example.demo.controller.ro.InsertRo;
import com.example.demo.service.impl.TestOtherServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author huangke
 * @description test
 * @date 2020/12/30
 */
@RestController
public class TestController {

    @Autowired
    @Qualifier("testOtherService")
    private TestOtherServiceImpl testOtherService;

    @GetMapping("/test1")
    public Object test1() {
        return this.testOtherService.get();
    }

    @PostMapping("/test2/{id}")
    public Object test2(@PathVariable("id") int id) throws ExecutionException, InterruptedException {
        return this.testOtherService.delete(id).get();
    }

    @GetMapping("/")
    public Object test() {
        return "Hello, World";
    }

    /**
    * 必传可以为""不能为null
    **/
    @GetMapping("/test3")
    public Object test3(@RequestParam("name") String name) {
        return "Hello, World";
    }

    /**
    * 校验参数
    **/
    @PostMapping("/test4")
    public Object test3(@RequestBody @Valid InsertRo insertRo) {
        String s = JSON.toJSONString(insertRo);
        System.out.println(s);
        return insertRo;
    }
    /**
    * 校验参数
    **/
    @PostMapping("/test5")
    public InsertRo test4() {
        InsertRo insertRo = new InsertRo();
//        insertRo.setAa(new BigDecimal("1E+2"));
        return insertRo;
    }
    /**
    * 校验参数
    **/
    @PostMapping("/test6")
    @PreAuthorize("@ss.hasPermi('sss')")
    public String test5() {
        InsertRo insertRo = new InsertRo();
        insertRo.setAa(new BigDecimal("1E+2"));
        return "insertRo";
    }
    /**
    * 校验参数
    **/
    @GetMapping("/async")
    public List< String> testAsync() {
        return testOtherService.testAsync();
    }

}